﻿<?php
include 'connectdb.php';
include 'base.php';
include 'requireLogin.php';
?>
<?php
if (isset ($_POST['ok_button'])){
	$varDate = $_POST['a_date'];
	$varDate1 = $_POST['i_date'];
	$skSQL =" SELECT bill.*,customer.* from bill,customer where bill.date <'" .$varDate. "' and bill.date >'" .$varDate1."' and customer.code = bill.customer_code and bill.status='1'";
	$result = mysql_query($skSQL);
	if(mysql_num_rows($result) > 0){
		echo"<b>Thống kê khách hàng từ ngày $varDate1 đến ngày $varDate </b>";
		echo"<table border = '1'>
		<tr>
		<th>Mã khách hàng</th>
		<th>Tên khách hàng</th>
		<th>Thông tin khách hàng</th>
		<th>Doanh thu từ khách hàng</th>
		<th>Lãi suất từ khách hàng</th>
		</tr>";
		while($row = mysql_fetch_array($result)){
			$sSQL = "select * from product where product.code = '".$row['product_code']."'";
			$subResult = mysql_query($sSQL);
			if(mysql_num_rows($subResult) > 0){
				while($row1 = mysql_fetch_array($subResult)){
					if($row['product_code'] == $row1['code']){
						$temp = $row['quantity']*$row1['sale_price'] - $row['quantity']*$row1['sale_price']*$row['discount']/100;
                        $temp1= $row['quantity']*$row1['import_price'];
                        $temp2= $temp-$temp1;
						echo"<tr>";
						echo"<td>".$row['code']."</td>";
						echo"<td>".$row['name']."</td>";
						echo"<td>".$row['information']."</td>";
						echo"<td>".number_format($temp,3)." VND"."</td>";
						echo"<td>".number_format($temp2,3)." VND"."</td>";
						echo"</tr>";
					}
				}
			}
		}
		echo"</table>";
	}
}
?>


<script language = "JavaScript" type = "text/javascript">
	$(document).ready(function(){
		$("#i_date").datepicker();
		$("#a_date").datepicker();
	});
</script>

<form method = "post" action ="">
	<div class = "form_settings">
		<p><span>Thống kê từ</span><input type ="text" name = "i_date" id  = "i_date" value = ""></p>
		<p><span>Đến trước ngày</span><input type = "text" name = "a_date" id = "a_date" value ="<?php echo date("Y-m-d");?>"></p>
		<span>&nbsp;</span><input class = "submit" type = "submit" name = "ok_button" id = "submit" value = "OK"/>
	</div>
</form>
<?php include 'footer.php';?>